$(function(){
	
	var newAddr = "";
	var newAddrName = "";
	var newStart = "";
	var newStartName = "";
	var newEnd = "";
	var newEndName = "";
	var searchAddr=""
	
	//点击地址输入框跳转至地图搜索页
	$(document).on("click",".addr-ipt",function(){
		var thisName=$(this).attr("name");
		if(thisName == "urbanStart"){
			searchAddr = "urbanStart";
		}
		else if(thisName == "nonurbanStart"){
			searchAddr = "nonurbanStart";
		}
		else{
			searchAddr = "nonurbanEnd";
		}
		$.router.load("searchAddress.html",true);
	})
	
	//地址页面点击了结果列表获取相应的id
	$(document).on("click",".address-box a",function(){
		var addrId =$(this).attr("id"),
			addrName = $(this).find("span").text();
		if(searchAddr=="urbanStart"){
			newAddr = addrId;
			newAddrName = addrName
		}
		else if(searchAddr=="nonurbanStart"){
			newStart = addrId;
			newStartName = addrName;
		}
		else{
			newEnd = addrId;
			newEndName = addrName;
		}
		$.router.back();
	})
	
	//返回到市区模式时将地址id赋值给起点输入框
	$(document).on("pageAnimationEnd","#urbanPage",function(){
		if(newAddr != ""){
			$("[name='urbanStart']").val(newAddrName);
			$("[name='urbanStart']").attr("addr",newAddr);
		}
	})
	
	//返回到非市区模式时将地址id赋值给起点和终点输入框
	$(document).on("pageAnimationEnd","#nonurbanPage",function(){
		if(newStart != ""){
			$("[name='nonurbanStart']").val(newStartName);
			$("[name='nonurbanStart']").attr("addr",newStart);
		}
		if(newEnd != ""){
			$("[name='nonurbanEnd']").val(newEndName);
			$("[name='nonurbanEnd']").attr("addr",newEnd);
		}
	})
	
	$.init();
})